package com.lwm.stream;

import com.lwm.entity.Employee;
import com.lwm.entity.Status;
import org.junit.Test;

import java.util.Arrays;
import java.util.List;
import java.util.Optional;

/**
 * @author liweimin
 * @version 1.0
 * @date 2020/9/7 11:38
 */
public class FindAndMatchTest {
    List<Employee> employeeList = Arrays.asList(
            new Employee("张三", 23, 6433, Status.BUSY),
            new Employee("张三1", 33, 4433,Status.FREE),
            new Employee("张三2", 63, 65333,Status.BUSY),
            new Employee("张三3", 43, 5333,Status.FREE),
            new Employee("张三4", 36, 4233,Status.VACATION)
    );
    @Test
    public void test01(){
        boolean b = employeeList.stream().allMatch((e) -> e.getStatus().equals(Status.FREE));
        System.out.println(b);
        boolean b1 = employeeList.stream().anyMatch((e) -> e.getStatus().equals(Status.BUSY));
        System.out.println(b1);
        boolean b2 = employeeList.stream().noneMatch((e) -> e.getStatus().equals(Status.FREE));
        System.out.println(b2);
        Optional<Employee> first = employeeList.stream().sorted((e1, e2)->Double.compare(e1.getSalary(), e2.getSalary())).findFirst();
//        first.orElse() findany----》并行
        System.out.println(first.get().toString());
        Optional<Employee> any = employeeList.stream().filter(e -> e.getStatus().equals(Status.FREE)).findAny();
        System.out.println(any.get());
    }
    @Test
    public void test02(){
        long count = employeeList.stream().count();
        System.out.println(count);

        Optional<Employee> max = employeeList.stream().max((a, b) -> Double.compare(a.getSalary(), b.getSalary()));
        System.out.println(max.get().toString());
        Optional<Double> max1 = employeeList.stream().map(Employee::getSalary).max(Double::compareTo);
        System.out.println(max1.get());
    }
}
